/**
 * com.sunrise.commons.dao.dialect.OracleDialect.java
 */
package com.mbmed.doctor.commons.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

 /**
 * @file  SqlserverDialect.java
 * @author yangxiaozuo(viscar)
 * @version 0.1
 * @todo sqlserver方言处理
 * Copyright(C), 2013-2014
 *			Guangzhou Sunrise Electronics Development Co., Ltd.
 */
public class SqlserverDialect extends Dialect {

	private static final Logger log = LoggerFactory.getLogger( SqlserverDialect.class );

	public String getLimitString(String sql, int offset, int limit) {
		sql = sql.trim();   
        StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);   
        pagingSelect.append("select * from ( select *,ROW_NUMBER() as rank from (");
        pagingSelect.append(sql);
        pagingSelect.append(" ) ) as a where a.rank between "+offset+" and  "+limit+" ");   
        if(log.isDebugEnabled()){
        	log.debug(pagingSelect.toString());
        }
        return pagingSelect.toString(); 
	}

	public static void main(String...args){
		SqlserverDialect db=new SqlserverDialect();
//		System.out.println(db.getLimitString("select * from test", 10, 5));
	}

}
